package threadPoolExecutorDemo;

import java.util.concurrent.*;

public class Dmeo4 {
    public static void main(String[] args) {
        //当任务队列满则抛出异常
        RejectedExecutionHandler handler = new ThreadPoolExecutor.AbortPolicy();
        ThreadPoolExecutor poolExecutor=new ThreadPoolExecutor(
                2,//核心线程数
                4, // 最大线程数
                60, // 空闲线程存活时间
                TimeUnit.SECONDS, // 时间单位
                new LinkedBlockingQueue<>(2), // 任务队列，容量为 2
                Executors.defaultThreadFactory(), // 默认线程工厂
                handler
        );

        for (int i = 0; i < 100; i++) {
            poolExecutor.submit(()->{
                System.out.println( Thread.currentThread().getName());
            });
        }
    }
}
